package com.first.dao.impl;


import com.first.dao.BOrderWjDao;
import com.first.entity.BOrderWj;
import com.first.util.DBUtil;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public class BOrderWjDaoImpl implements BOrderWjDao {
    /**
     * 获取订单详细信息
     *
     * @param bOrderWj
     * @return
     */
    @Override
    public List<Map> getAllBOrderWj(BOrderWj bOrderWj) {
        String sql="select o.orderid,b.bookid,bookname,author,o.count,press from b_order o,book b where o.bookid=b.bookid";
        List<Map> list = DBUtil.queryListMap(sql);
        return list;

    }

    /**
     * 添加订单详情表
     * @param bOrderWj
     * @return
     */
    @Override
    public double addOrderWj( BOrderWj bOrderWj) {
        String s = "select  inprice from book b where b.bookid=?";
        List<List> lists = DBUtil.queryList(s, bOrderWj.getBookid());
        Object o = lists.get(0).get(0);
        double i1 = Double.parseDouble(o+"");

        String sql="insert into b_order_wj values(?,?,?,?,null)";
        int i = DBUtil.update(sql, bOrderWj.getOrderid(), bOrderWj.getBookid(), bOrderWj.getCount() ,i1*bOrderWj.getCount());
        return i1*bOrderWj.getCount();
    }
}
